
const extraProjectArr =  ['11105', '10907', '10208', '10700', '11219', '11104', '11107', '10209', '10300',
'11106', '10100', '10204','11300','11302','11400'];
class JiraTool {

  bodyParser(data) {
    const ret = JSON.parse(data.body);
    return ret;
  };

  addParams(str, data) {

    for (let key in data) {
      // console.log(`data is=${data},\n key is=${key}`)
      let paramStr = `&${key}=${data[key]}`;
      paramStr = paramStr.replace(/\//g, '\\u002f')
      str += paramStr;
      //  console.log(`str=======${str}`)
    }
    return str;
  }

  sortByKey(arr, key) {
    let ret = arr;
    for (var j = 0; j < ret.length - 1; j++) {
      for (var i = 0; i < ret.length - 1 - j; i++) {
        if (parseInt(ret[i][key]) < parseInt(ret[i + 1][key])) {
          var temp = ret[i];
          ret[i] = ret[i + 1];
          ret[i + 1] = temp;
        };
      };
    };
    return ret;
  };

  // 过滤器

  async filterID(arrya) {

    let newarry = [];
    // let extraArr = ['11105', '10907', '10208', '10700', '11219', '11104', '11107', '10209', '10300',
    //   '11106', '10100', '10204'];
    arrya.forEach(item => {
      for (let i of extraProjectArr) {
        if (item.id == i) {
          newarry.push(item)
        }

      }

    });
  
    return newarry;
  }

  async getExtraProjectArr(){
    return extraProjectArr;
  }

  // 待参数过滤器
  async filterIDParm(arrya) {
   // console.log('调用第三个~')

    let newarry = [];
    let extraArr = ['10902', '11103', '10500', '10903', '10202', '10203', '10908', '10200',
      '10101', '11003', '10201', '10905', '10400', '11101', '11102', '10004', '10906', '10002',
      '10401', '10600', '10904', '10403', '10802', '11000'
    ];

    arrya.forEach((item, xb) => {

      //  console.log(`item1=${item[xb]}`)

      item.forEach(item2 => {
        // console.log('item=',item)
        let isSkip = false;
        for (let z = 0; z < extraArr.length; z++) {
          if (extraArr[z] == item2.id) {
            isSkip = true;
          }
        }
        if (!isSkip) {

          newarry.push(item2);
        }

      })

    })



    return newarry;
  }

  //  传递ID入口过滤
  async filterIDParms(id) {
    let newarry = [];
    let filterIDArry = [];
    filterIDArry.push(id);

    let extraArr =['11105', '10907', '10208', '10700', '11219', '11104', '11107', '10209', '10300',
    '11106', '10100', '10204'];

    filterIDArry.forEach(item => {
      for (let i of extraArr) {
        if (item == i) {
          newarry.push(item)

        }

      }

    });

    return newarry;
  }



  // 排序
  async setarry(ret) {
    // const ret= [ { name: 'Education', idTotal: 228 },
    //  { name: 'EduWebsite', idTotal: 1 },
    //  { name: 'IDE', idTotal: 3 },
    //  { name: 'IoT', idTotal: 1 },
    //  { name: 'LaserPrinter', idTotal: 53 },
    //  { name: 'MakeblockForAndroid', idTotal: 140 },
    //  { name: 'MakeblockForIOS', idTotal: 62 },
    //  { name: 'MakeX', idTotal: 241 },
    //  { name: 'mbclass', idTotal: 44 },
    //  { name: 'mblock', idTotal: 632 },
    //  { name: 'mBlockApp', idTotal: 0 },
    //  { name: 'mBlockForum', idTotal: 0 },
    //  { name: 'Neurons', idTotal: 145 },
    //  { name: 'New Education', idTotal: 1 },
    //  { name: 'TestDev', idTotal: 0 },
    //  { name: 'Unity3D', idTotal: 3 } ]
    let sortret = ret.sort((a, b) => b.idTotal - a.idTotal)

    //console.log('sortret',sortret)
    return sortret;




  }







};

module.exports = new JiraTool();